import { IGetOpUnionBaseinfoRes, getUserGet, IGetUserGetRes } from '@/api';
// import { KeycloakInstance } from 'keycloak-js';
import { defineStore } from 'pinia';

type TPlatform = 'MCH'; // 操作平台 MCH - 商户平台

interface IRegister {
  isHaveReg: boolean;
}
export interface IWhiteUserConfig {
  userId: number;
  dashboard: number[];
}
export type IAuthList = Required<IGetOpUnionBaseinfoRes>['authList'];

interface IUserInfo {
  // mcisaas: IGetOpUnionBaseinfoRes;
  mcisaas: IGetUserGetRes;
  // keycloak: Partial<KeycloakInstance>;
  platform: TPlatform;
  register: IRegister;
  authList: IAuthList;
  // whiteUserConfig: IWhiteUserConfig;
}

export const useAppStore = defineStore('appStore', {
  state(): IUserInfo {
    return {
      mcisaas: {},
      // keycloak: {},
      platform: 'MCH',
      register: {
        isHaveReg: false
      },
      authList: [],
      // whiteUserConfig: {
      //   userId: -1,
      //   dashboard: []
      // }
    };
  },
  actions: {
    async getMcisaas() {
      // this.mcisaas = await getOpUnionBaseinfo();
      // if (this.mcisaas.userId) {
      //   this.whiteUserConfig.userId = this.mcisaas.userId;
      // }
      // this.whiteUserConfig.dashboard = await getPayFinanceUserWhitelistQueryUserWhitelist({ funcType: 'BSM' });
      // this.authList = this.mcisaas.authList?.filter((item) => SYSTEM_CODE === item.systemCode) ?? [];
      this.mcisaas = await getUserGet();
    },

    logout() {
      sessionStorage.clear();
      localStorage.clear();
    }
  }
});
